import React from 'react'
import { Modal ,Button , Form, Input } from 'antd';

function My_modal({flag,handleOk,handleCancel,obj,setDataValue}) {
    // console.log(obj);
    // let {flag,handleOk,handleCancel} = props

    //提交表单 验证成功后执行的函数
    const onFinish = (values) => {
        console.log('Success:', values.username);
        setDataValue(values.username)
        handleOk()
    };
    //提交表单 验证失败执行的函数 
    const onFinishFailed = (errorInfo) => {
        console.log('Failed:', errorInfo);
    };
    
   return (
    <div>
        <Modal destroyOnClose={true} footer={null} maskClosable={false} title="2001A 2001B" visible={flag} onOk={handleOk} onCancel={handleCancel}>
        <Form
            name="basic"
            labelCol={{
                span: 8,
            }}
            wrapperCol={{
                span: 16,
            }}
            //设置表单回显值
            initialValues={{
                username: obj,
            }}
            onFinish={onFinish}
            onFinishFailed={onFinishFailed}
            autoComplete="off"
            >
            <Form.Item
                label="内容"
                name="username"
                rules={[
                {
                    required: true,
                    message: 'Please input your username!',
                },
                ]}
            >
                <Input />
            </Form.Item>

            <Form.Item
                wrapperCol={{
                offset: 8,
                span: 16,
                }}
            >
                 <Button type="primary" onClick={handleCancel}>
                    取消
                </Button>
                <Button type="primary" htmlType="submit">
                    确认
                </Button>
            </Form.Item>
        </Form>
      </Modal>
    </div>
  )
}

export default My_modal